home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / gnustuff / tos / bison / bison1~1.zoo / bison.simple < prev    next >
Encoding:
Text File  |  1991-09-25  |  14.5 KB  |  615 lines

  1. /* -*-C-*-  Note some compilers choke on comments on `#line' lines.  */
  2. #line 3 "bison.simple"
  3.  
  4. /* Skeleton output parser for bison,
  5.    Copyright (C) 1984, 1989, 1990 Bob Corbett and Richard Stallman
  6.  
  7.    This program is free software; you can redistribute it and/or modify
  8.    it under the terms of the GNU General Public License as published by
  9.    the Free Software Foundation; either version 1, or (at your option)
  10.    any later version.
  11.  
  12.    This program is distributed in the hope that it will be useful,
  13.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.    GNU General Public License for more details.
  16.  
  17.    You should have received a copy of the GNU General Public License
  18.    along with this program; if not, write to the Free Software
  19.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  20.  
  21.  
  22. #ifndef alloca
  23. #ifdef __GNUC__
  24. #define alloca __builtin_alloca
  25. #else /* Not GNU C.  */
  26. #if (!defined (__STDC__) && defined (sparc)) || defined (__sparc__)
  27. #include <alloca.h>
  28. #else /* Not sparc */
  29. #ifdef MSDOS
  30. #include <malloc.h>
  31. #endif /* MSDOS */
  32. #ifdef atarist
  33. #include <stdlib.h>
  34. #include <string.h>
  35. #include <unistd.h>
  36. #include <memory.h>
  37. #endif /* atarist */
  38. #endif /* Not sparc.  */
  39. #endif /* Not GNU C.  */
  40. #endif /* alloca not defined.  */
  41.  
  42. /* This is the parser code that is written into each bison parser
  43.   when the %semantic_parser declaration is not specified in the grammar.
  44.   It was written by Richard Stallman by simplifying the hairy parser
  45.   used when %semantic_parser is specified.  */
  46.  
  47. /* Note: there must be only one dollar sign in this file.
  48.    It is replaced by the list of actions, each action
  49.    as one case of the switch.  */
  50.  
  51. #define yyerrok        (yyerrstatus = 0)
  52. #define yyclearin    (yychar = YYEMPTY)
  53. #define YYEMPTY        -2
  54. #define YYEOF        0
  55. #define YYACCEPT    return(0)
  56. #define YYABORT     return(1)
  57. #define YYERROR        goto yyerrlab1
  58. /* Like YYERROR except do call yyerror.
  59.    This remains here temporarily to ease the
  60.    transition to the new meaning of YYERROR, for GCC.
  61.    Once GCC version 2 has supplanted version 1, this can go.  */
  62. #define YYFAIL        goto yyerrlab
  63. #define YYRECOVERING()  (!!yyerrstatus)
  64. #define YYBACKUP(token, value) \
  65. do                                \
  66.   if (yychar == YYEMPTY && yylen == 1)                \
  67.     { yychar = (token), yylval = (value);            \
  68.       yychar1 = YYTRANSLATE (yychar);                \
  69.       YYPOPSTACK;                        \
  70.       goto yybackup;                        \
  71.     }                                \
  72.   else                                \
  73.     { yyerror ("syntax error: cannot back up"); YYERROR; }    \
  74. while (0)
  75.  
  76. #define YYTERROR    1
  77. #define YYERRCODE    256
  78.  
  79. #ifndef YYPURE
  80. #define YYLEX        yylex()
  81. #endif
  82.  
  83. #ifdef YYPURE
  84. #ifdef YYLSP_NEEDED
  85. #define YYLEX        yylex(&yylval, &yylloc)
  86. #else
  87. #define YYLEX        yylex(&yylval)
  88. #endif
  89. #endif
  90.  
  91. /* If nonreentrant, generate the variables here */
  92.  
  93. #ifndef YYPURE
  94.  
  95. int    yychar;            /*  the lookahead symbol        */
  96. YYSTYPE    yylval;            /*  the semantic value of the        */
  97.                 /*  lookahead symbol            */
  98.  
  99. #ifdef YYLSP_NEEDED
  100. YYLTYPE yylloc;            /*  location data for the lookahead    */
  101.                 /*  symbol                */
  102. #endif
  103.  
  104. int yynerrs;            /*  number of parse errors so far       */
  105. #endif  /* not YYPURE */
  106.  
  107. #if YYDEBUG != 0
  108. int yydebug;            /*  nonzero means print parse trace    */
  109. /* Since this is uninitialized, it does not stop multiple parsers
  110.    from coexisting.  */
  111. #endif
  112.  
  113. /*  YYINITDEPTH indicates the initial size of the parser's stacks    */
  114.  
  115. #ifndef    YYINITDEPTH
  116. #define YYINITDEPTH 200
  117. #endif
  118.  
  119. /*  YYMAXDEPTH is the maximum size the stacks can grow to
  120.     (effective only if the built-in stack extension method is used).  */
  121.  
  122. #if YYMAXDEPTH == 0
  123. #undef YYMAXDEPTH
  124. #endif
  125.  
  126. #ifndef YYMAXDEPTH
  127. #define YYMAXDEPTH 10000
  128. #endif
  129.  
  130. #ifndef __cplusplus
  131.  
  132. /* This is the most reliable way to avoid incompatibilities
  133.    in available built-in functions on various systems.  */
  134. static void
  135. __yy_bcopy (from, to, count)
  136.      char *from;
  137.      char *to;
  138.      int count;
  139. {
  140.   register char *f = from;
  141.   register char *t = to;
  142.   register int i = count;
  143.  
  144.   while (i-- > 0)
  145.     *t++ = *f++;
  146. }
  147.  
  148. #else /* __cplusplus */
  149.  
  150. /* This is the most reliable way to avoid incompatibilities
  151.    in available built-in functions on various systems.  */
  152. static void
  153. __yy_bcopy (char *from, char *to, int count)
  154. {
  155.   register char *f = from;
  156.   register char *t = to;
  157.   register int i = count;
  158.  
  159.   while (i-- > 0)
  160.     *t++ = *f++;
  161. }
  162.  
  163. #endif
  164.  
  165. #line 160 "bison.simple"
  166. int
  167. yyparse()
  168. {
  169.   register int yystate;
  170.   register int yyn;
  171.   register short *yyssp;
  172.   register YYSTYPE *yyvsp;
  173.   int yyerrstatus;    /*  number of tokens to shift before error messages enabled */
  174.   int yychar1;        /*  lookahead token as an internal (translated) token number */
  175.  
  176.   short    yyssa[YYINITDEPTH];    /*  the state stack            */
  177.   YYSTYPE yyvsa[YYINITDEPTH];    /*  the semantic value stack        */
  178.  
  179.   short *yyss = yyssa;        /*  refer to the stacks thru separate pointers */
  180.   YYSTYPE *yyvs = yyvsa;    /*  to allow yyoverflow to reallocate them elsewhere */
  181.  
  182. #ifdef YYLSP_NEEDED
  183.   YYLTYPE *yyls = yylsa;
  184.   YYLTYPE *yylsp;
  185.   YYLTYPE yylsa[YYINITDEPTH];    /*  the location stack            */
  186.  
  187. #define YYPOPSTACK   (yyvsp--, yysp--, yylsp--)
  188. #else
  189. #define YYPOPSTACK   (yyvsp--, yysp--)
  190. #endif
  191.  
  192.   int yystacksize = YYINITDEPTH;
  193.  
  194. #ifdef YYPURE
  195.   int yychar;
  196.   YYSTYPE yylval;
  197.   int yynerrs;
  198. #ifdef YYLSP_NEEDED
  199.   YYLTYPE yylloc;
  200. #endif
  201. #endif
  202.  
  203.   YYSTYPE yyval;        /*  the variable used to return        */
  204.                 /*  semantic values from the action    */
  205.                 /*  routines                */
  206.  
  207.   int yylen;
  208.  
  209. #if YYDEBUG != 0
  210.   if (yydebug)
  211.     fprintf(stderr, "Starting parse\n");
  212. #endif
  213.  
  214.   yystate = 0;
  215.   yyerrstatus = 0;
  216.   yynerrs = 0;
  217.   yychar = YYEMPTY;        /* Cause a token to be read.  */
  218.  
  219.   /* Initialize stack pointers.
  220.      Waste one element of value and location stack
  221.      so that they stay on the same level as the state stack.  */
  222.  
  223.   yyssp = yyss - 1;
  224.   yyvsp = yyvs;
  225. #ifdef YYLSP_NEEDED
  226.   yylsp = yyls;
  227. #endif
  228.  
  229. /* Push a new state, which is found in  yystate  .  */
  230. /* In all cases, when you get here, the value and location stacks
  231.    have just been pushed. so pushing a state here evens the stacks.  */
  232. yynewstate:
  233.  
  234.   *++yyssp = yystate;
  235.  
  236.   if (yyssp >= yyss + yystacksize - 1)
  237.     {
  238.       /* Give user a chance to reallocate the stack */
  239.       /* Use copies of these so that the &'s don't force the real ones into memory. */
  240.       YYSTYPE *yyvs1 = yyvs;
  241.       short *yyss1 = yyss;
  242. #ifdef YYLSP_NEEDED
  243.       YYLTYPE *yyls1 = yyls;
  244. #endif
  245.  
  246.       /* Get the current used size of the three stacks, in elements.  */
  247.       int size = yyssp - yyss + 1;
  248.  
  249. #ifdef yyoverflow
  250.       /* Each stack pointer address is followed by the size of
  251.      the data in use in that stack, in bytes.  */
  252.       yyoverflow("parser stack overflow",
  253.          &yyss1, size * sizeof (*yyssp),
  254.          &yyvs1, size * sizeof (*yyvsp),
  255. #ifdef YYLSP_NEEDED
  256.          &yyls1, size * sizeof (*yylsp),
  257. #endif
  258.          &yystacksize);
  259.  
  260.       yyss = yyss1; yyvs = yyvs1;
  261. #ifdef YYLSP_NEEDED
  262.       yyls = yyls1;
  263. #endif
  264. #else /* no yyoverflow */
  265.       /* Extend the stack our own way.  */
  266.       if (yystacksize >= YYMAXDEPTH)
  267.     {
  268.       yyerror("parser stack overflow");
  269.       return 2;
  270.     }
  271.       yystacksize *= 2;
  272.       if (yystacksize > YYMAXDEPTH)
  273.     yystacksize = YYMAXDEPTH;
  274.       yyss = (short *) alloca (yystacksize * sizeof (*yyssp));
  275.       __yy_bcopy ((char *)yyss1, (char *)yyss, size * sizeof (*yyssp));
  276.       yyvs = (YYSTYPE *) alloca (yystacksize * sizeof (*yyvsp));
  277.       __yy_bcopy ((char *)yyvs1, (char *)yyvs, size * sizeof (*yyvsp));
  278. #ifdef YYLSP_NEEDED
  279.       yyls = (YYLTYPE *) alloca (yystacksize * sizeof (*yylsp));
  280.       __yy_bcopy ((char *)yyls1, (char *)yyls, size * sizeof (*yylsp));
  281. #endif
  282. #endif /* no yyoverflow */
  283.  
  284.       yyssp = yyss + size - 1;
  285.       yyvsp = yyvs + size - 1;
  286. #ifdef YYLSP_NEEDED
  287.       yylsp = yyls + size - 1;
  288. #endif
  289.  
  290. #if YYDEBUG != 0
  291.       if (yydebug)
  292.     fprintf(stderr, "Stack size increased to %d\n", yystacksize);
  293. #endif
  294.  
  295.       if (yyssp >= yyss + yystacksize - 1)
  296.     YYABORT;
  297.     }
  298.  
  299. #if YYDEBUG != 0
  300.   if (yydebug)
  301.     fprintf(stderr, "Entering state %d\n", yystate);
  302. #endif
  303.  
  304.  yybackup:
  305.  
  306. /* Do appropriate processing given the current state.  */
  307. /* Read a lookahead token if we need one and don't already have one.  */
  308. /* yyresume: */
  309.  
  310.   /* First try to decide what to do without reference to lookahead token.  */
  311.  
  312.   yyn = yypact[yystate];
  313.   if (yyn == YYFLAG)
  314.     goto yydefault;
  315.  
  316.   /* Not known => get a lookahead token if don't already have one.  */
  317.  
  318.   /* yychar is either YYEMPTY or YYEOF
  319.      or a valid token in external form.  */
  320.  
  321.   if (yychar == YYEMPTY)
  322.     {
  323. #if YYDEBUG != 0
  324.       if (yydebug)
  325.     fprintf(stderr, "Reading a token: ");
  326. #endif
  327.       yychar = YYLEX;
  328.     }
  329.  
  330.   /* Convert token to internal form (in yychar1) for indexing tables with */
  331.  
  332.   if (yychar <= 0)        /* This means end of input. */
  333.     {
  334.       yychar1 = 0;
  335.       yychar = YYEOF;        /* Don't call YYLEX any more */
  336.  
  337. #if YYDEBUG != 0
  338.       if (yydebug)
  339.     fprintf(stderr, "Now at end of input.\n");
  340. #endif
  341.     }
  342.   else
  343.     {
  344.       yychar1 = YYTRANSLATE(yychar);
  345.  
  346. #if YYDEBUG != 0
  347.       if (yydebug)
  348.     fprintf(stderr, "Next token is %d (%s)\n", yychar, yytname[yychar1]);
  349. #endif
  350.     }
  351.  
  352.   yyn += yychar1;
  353.   if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1)
  354.     goto yydefault;
  355.  
  356.   yyn = yytable[yyn];
  357.  
  358.   /* yyn is what to do for this token type in this state.
  359.      Negative => reduce, -yyn is rule number.
  360.      Positive => shift, yyn is new state.
  361.        New state is final state => don't bother to shift,
  362.        just return success.
  363.      0, or most negative number => error.  */
  364.  
  365.   if (yyn < 0)
  366.     {
  367.       if (yyn == YYFLAG)
  368.     goto yyerrlab;
  369.       yyn = -yyn;
  370.       goto yyreduce;
  371.     }
  372.   else if (yyn == 0)
  373.     goto yyerrlab;
  374.  
  375.   if (yyn == YYFINAL)
  376.     YYACCEPT;
  377.  
  378.   /* Shift the lookahead token.  */
  379.  
  380. #if YYDEBUG != 0
  381.   if (yydebug)
  382.     fprintf(stderr, "Shifting token %d (%s), ", yychar, yytname[yychar1]);
  383. #endif
  384.  
  385.   /* Discard the token being shifted unless it is eof.  */
  386.   if (yychar != YYEOF)
  387.     yychar = YYEMPTY;
  388.  
  389.   *++yyvsp = yylval;
  390. #ifdef YYLSP_NEEDED
  391.   *++yylsp = yylloc;
  392. #endif
  393.  
  394.   /* count tokens shifted since error; after three, turn off error status.  */
  395.   if (yyerrstatus) yyerrstatus--;
  396.  
  397.   yystate = yyn;
  398.   goto yynewstate;
  399.  
  400. /* Do the default action for the current state.  */
  401. yydefault:
  402.  
  403.   yyn = yydefact[yystate];
  404.   if (yyn == 0)
  405.     goto yyerrlab;
  406.  
  407. /* Do a reduction.  yyn is the number of a rule to reduce with.  */
  408. yyreduce:
  409.   yylen = yyr2[yyn];
  410.   yyval = yyvsp[1-yylen]; /* implement default value of the action */
  411.  
  412. #if YYDEBUG != 0
  413.   if (yydebug)
  414.     {
  415.       int i;
  416.  
  417.       fprintf (stderr, "Reducing via rule %d (line %d), ",
  418.            yyn, yyrline[yyn]);
  419.  
  420.       /* Print the symboles being reduced, and their result.  */
  421.       for (i = yyprhs[yyn]; yyrhs[i] > 0; i++)
  422.     fprintf (stderr, "%s ", yytname[yyrhs[i]]);
  423.       fprintf (stderr, " -> %s\n", yytname[yyr1[yyn]]);
  424.     }
  425. #endif
  426.  
  427. $   /* the action file gets copied in in place of this dollarsign */
  428. #line 423 "bison.simple"
  429.  
  430.   yyvsp -= yylen;
  431.   yyssp -= yylen;
  432. #ifdef YYLSP_NEEDED
  433.   yylsp -= yylen;
  434. #endif
  435.  
  436. #if YYDEBUG != 0
  437.   if (yydebug)
  438.     {
  439.       short *ssp1 = yyss - 1;
  440.       fprintf (stderr, "state stack now");
  441.       while (ssp1 != yyssp)
  442.     fprintf (stderr, " %d", *++ssp1);
  443.       fprintf (stderr, "\n");
  444.     }
  445. #endif
  446.  
  447.   *++yyvsp = yyval;
  448.  
  449. #ifdef YYLSP_NEEDED
  450.   yylsp++;
  451.   if (yylen == 0)
  452.     {
  453.       yylsp->first_line = yylloc.first_line;
  454.       yylsp->first_column = yylloc.first_column;
  455.       yylsp->last_line = (yylsp-1)->last_line;
  456.       yylsp->last_column = (yylsp-1)->last_column;
  457.       yylsp->text = 0;
  458.     }
  459.   else
  460.     {
  461.       yylsp->last_line = (yylsp+yylen-1)->last_line;
  462.       yylsp->last_column = (yylsp+yylen-1)->last_column;
  463.     }
  464. #endif
  465.  
  466.   /* Now "shift" the result of the reduction.
  467.      Determine what state that goes to,
  468.      based on the state we popped back to
  469.      and the rule number reduced by.  */
  470.  
  471.   yyn = yyr1[yyn];
  472.  
  473.   yystate = yypgoto[yyn - YYNTBASE] + *yyssp;
  474.   if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)
  475.     yystate = yytable[yystate];
  476.   else
  477.     yystate = yydefgoto[yyn - YYNTBASE];
  478.  
  479.   goto yynewstate;
  480.  
  481. yyerrlab:   /* here on detecting error */
  482.  
  483.   if (! yyerrstatus)
  484.     /* If not already recovering from an error, report this error.  */
  485.     {
  486.       ++yynerrs;
  487.  
  488. #ifdef YYERROR_VERBOSE
  489.       yyn = yypact[yystate];
  490.  
  491.       if (yyn > YYFLAG && yyn < YYLAST)
  492.     {
  493.       int size = 0;
  494.       char *msg;
  495.       int x, count;
  496.  
  497.       count = 0;
  498.       for (x = 0; x < (sizeof(yytname) / sizeof(char *)); x++)
  499.         if (yycheck[x + yyn] == x)
  500.           size += strlen(yytname[x]) + 15, count++;
  501.       msg = (char *) xmalloc(size + 15);
  502.       strcpy(msg, "parse error");
  503.  
  504.       if (count < 5)
  505.         {
  506.           count = 0;
  507.           for (x = 0; x < (sizeof(yytname) / sizeof(char *)); x++)
  508.         if (yycheck[x + yyn] == x)
  509.           {
  510.             strcat(msg, count == 0 ? ", expecting `" : " or `");
  511.             strcat(msg, yytname[x]);
  512.             strcat(msg, "'");
  513.             count++;
  514.           }
  515.         }
  516.       yyerror(msg);
  517.       free(msg);
  518.     }
  519.       else
  520. #endif /* YYERROR_VERBOSE */
  521.     yyerror("parse error");
  522.     }
  523.  
  524. yyerrlab1:   /* here on error raised explicitly by an action */
  525.  
  526.   if (yyerrstatus == 3)
  527.     {
  528.       /* if just tried and failed to reuse lookahead token after an error, discard it.  */
  529.  
  530.       /* return failure if at end of input */
  531.       if (yychar == YYEOF)
  532.     YYABORT;
  533.  
  534. #if YYDEBUG != 0
  535.       if (yydebug)
  536.     fprintf(stderr, "Discarding token %d (%s).\n", yychar, yytname[yychar1]);
  537. #endif
  538.  
  539.       yychar = YYEMPTY;
  540.     }
  541.  
  542.   /* Else will try to reuse lookahead token
  543.      after shifting the error token.  */
  544.  
  545.   yyerrstatus = 3;        /* Each real token shifted decrements this */
  546.  
  547.   goto yyerrhandle;
  548.  
  549. yyerrdefault:  /* current state does not do anything special for the error token. */
  550.  
  551. #if 0
  552.   /* This is wrong; only states that explicitly want error tokens
  553.      should shift them.  */
  554.   yyn = yydefact[yystate];  /* If its default is to accept any token, ok.  Otherwise pop it.*/
  555.   if (yyn) goto yydefault;
  556. #endif
  557.  
  558. yyerrpop:   /* pop the current state because it cannot handle the error token */
  559.  
  560.   if (yyssp == yyss) YYABORT;
  561.   yyvsp--;
  562.   yystate = *--yyssp;
  563. #ifdef YYLSP_NEEDED
  564.   yylsp--;
  565. #endif
  566.  
  567. #if YYDEBUG != 0
  568.   if (yydebug)
  569.     {
  570.       short *ssp1 = yyss - 1;
  571.       fprintf (stderr, "Error: state stack now");
  572.       while (ssp1 != yyssp)
  573.     fprintf (stderr, " %d", *++ssp1);
  574.       fprintf (stderr, "\n");
  575.     }
  576. #endif
  577.  
  578. yyerrhandle:
  579.  
  580.   yyn = yypact[yystate];
  581.   if (yyn == YYFLAG)
  582.     goto yyerrdefault;
  583.  
  584.   yyn += YYTERROR;
  585.   if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR)
  586.     goto yyerrdefault;
  587.  
  588.   yyn = yytable[yyn];
  589.   if (yyn < 0)
  590.     {
  591.       if (yyn == YYFLAG)
  592.     goto yyerrpop;
  593.       yyn = -yyn;
  594.       goto yyreduce;
  595.     }
  596.   else if (yyn == 0)
  597.     goto yyerrpop;
  598.  
  599.   if (yyn == YYFINAL)
  600.     YYACCEPT;
  601.  
  602. #if YYDEBUG != 0
  603.   if (yydebug)
  604.     fprintf(stderr, "Shifting error token, ");
  605. #endif
  606.  
  607.   *++yyvsp = yylval;
  608. #ifdef YYLSP_NEEDED
  609.   *++yylsp = yylloc;
  610. #endif
  611.  
  612.   yystate = yyn;
  613.   goto yynewstate;
  614. }
  615.